package cn.worldyao.homework.controller;

import cn.worldyao.homework.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@Slf4j
public class StuViewController {

    public static String STU_PATH = "stu/";

    @RequestMapping("/slogin.html")
    public String sLogin(Model model) {
        log.info("\n-----sLogin-view-----\n");
        return STU_PATH + "stu-login";
    }

    @RequestMapping("/sregister.html")
    public String sRegister(Model model) {
        log.info("\n-----sRegister-view-----\n");
        return STU_PATH + "stu-register";
    }


    @RequestMapping("/sindex.html")
    public String sIndex(Model model, HttpSession session) {
        log.info("\n-----sIndex-view-----\n");
//        if (session.getAttribute("user") != null) {
        return STU_PATH + "stu-index";
//        } else {
//            return STU_PATH + "tea-login";
//        }
    }

    @RequestMapping("/smyclass.html")
    public String sMyClass(Model model, HttpSession session) {
        log.info("\n-----sMyClass-view-----\n");
        if (Tools.userIsStudent(session)) {
            return STU_PATH + "stu-myclass";
        } else {
            return STU_PATH + "stu-login";
        }
    }
}
